package com.ruoyi.cpsp.service.impl;

import com.ruoyi.cpsp.mapper.EvaluateRecordMapper;
import com.ruoyi.cpsp.mapper.EvaluateRecordToEmployeeMapper;
import com.ruoyi.cpsp.mapper.PerformanceHistoryMapper;
import com.ruoyi.cpsp.domain.EvaluateRecord;
import com.ruoyi.cpsp.domain.EvaluateRecordToEmployee;
import com.ruoyi.cpsp.domain.PerformanceHistory;
import com.ruoyi.cpsp.service.IDataAcquisition;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class DataAcquisition implements IDataAcquisition
{
    @Autowired
    private PerformanceHistoryMapper performanceHistoryMapper;

    @Autowired
    private EvaluateRecordMapper evaluateRecordMapper;

    @Autowired
    private EvaluateRecordToEmployeeMapper evaluateRecordToEmployeeMapper;

    private static final String BEGIN_YEAR = "beginYear";
    private static final String BEGIN_QUARTER = "beginQuarter";
    private static final String END_YEAR = "endYear";
    private static final String END_QUARTER = "endQuarter";
    private static final String EMPLOYEE_ID = "idCard";
    private static final String EMPLOYEE_NAME = "name";
    private static final String EMPLOYEE_DEPARTMENT = "department";
    private static final String EMPLOYEE_RECORD_ID = "evaluateRecordId";



    private Map<String, Object> conditionMap;

    public DataAcquisition()
    {
        conditionMap = new HashMap<>();
    }


    @Override
    public void setTime(int beginYear, int beginQuarter, int endYear, int endQuarter)
    {
        conditionMap.put(BEGIN_YEAR, beginYear);
        conditionMap.put(BEGIN_QUARTER, beginQuarter);
        conditionMap.put(END_YEAR, endYear);
        conditionMap.put(END_QUARTER, endQuarter);
    }

    @Override
    public void setEmployeeIdCard(String idCard)
    {
        conditionMap.put(EMPLOYEE_ID, idCard);
    }


    @Override
    public void setEmployeeName(String name)
    {
        conditionMap.put(EMPLOYEE_NAME, name);
    }

    @Override
    public void setEmployeeDepartment(String department)
    {
        conditionMap.put(EMPLOYEE_DEPARTMENT, department);
    }

    @Override
    public void setEvaluateRecordId(int evaluateRecordId)
    {
        conditionMap.put(EMPLOYEE_RECORD_ID, evaluateRecordId);
    }

    @Override
    public List<PerformanceHistory> getPerformanceHistorys()
    {
        return performanceHistoryMapper.selectPerformanceHistorys(conditionMap);
    }


    @Override
    public List<EvaluateRecord> getEvaluateRecords()
    {
        return null;
    }
    @Override
    public List<EvaluateRecordToEmployee> getEvaluateRecordToEmployees()
    {
        return evaluateRecordToEmployeeMapper.selectEvaluateRecordToEmployees(conditionMap);
    }

    public void clearConditionMap()
    {
        conditionMap.clear();
    }

    // 测试方法
//    public Object getValue(String key)
//    {
//        return conditionMap.get(key);
//    }
}
